package bbb;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;


public class J26_SungJukDAO {
	private String DRV = "oracle.jdbc.driver.OracleDriver";
	private String URL = "jdbc:oracle:thin:spirit/spirit@112.216.253.125:1521:xe";
	private String insertSQL = "insert into sungjuk1 values(exam.nextval,?,?,?,?,?,?,?, sysdate)";
	
	public boolean insertSungJuk(J26_SungJukvo sj){
		Connection conn = null;
		PreparedStatement pstmt = null;
		boolean result = false;
		try{
			conn = this.openDatebase();
			pstmt = conn.prepareStatement(insertSQL);
			
			pstmt.setString(1, sj.getName());
			pstmt.setString(2, sj.getKor());
			pstmt.setString(3, sj.getEng());
			pstmt.setString(4, sj.getMat());
			pstmt.setString(5, sj.getTot());
			pstmt.setString(6, sj.getAvg());
			pstmt.setString(7, sj.getGrd());
			
			pstmt.executeUpdate();
			result = true;
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			closeDatebase(conn, pstmt, null);
		}
		return result;
	}
	protected Connection openDatebase(){
		
		try{
			Class.forName(DRV);
			return DriverManager.getConnection(URL);
		}catch(Exception ex){
			ex.printStackTrace();
		}
			return null;
		}
	protected void closeDatebase(
		Connection c,PreparedStatement p, ResultSet r){
		if(r != null)try{r.close(); r = null;}catch(Exception e){}
		if(p != null)try{p.close(); p = null;}catch(Exception e){}
		if(c != null)try{c.close(); c = null;}catch(Exception e){}
		
	}

}
